package pe.gob.sedapal.scmultimedia.rcp.action;

import org.eclipse.jface.action.Action;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction;
import org.jpedal.PdfDecoder;

import pe.gob.sedapal.scmultimedia.rcp.view.servicios.PdfView;

public class EdgePageAction extends Action implements IWorkbenchAction {
	private static final String ID = "pe.gob.sedapal.scmultimedia.rcp.action.EdgePageAction";  
	
	private PdfDecoder decodePDF;
	private int page;
	
	public EdgePageAction(int page){  
		setId(ID);  
		this.page=page;
	}  
	@Override
	public void dispose() {
		// TODO Auto-generated method stub

	}
	@Override
	public void run() {
		PdfView view=(PdfView)PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(PdfView.ID);  
		decodePDF=view.getDecodePDF();		
		//currentPage=view.getCurrentPage();
		edgePage(view);
	}
	
	private void edgePage(PdfView view) {		
        try {
        	if(page==9){
        		page=decodePDF.getPageCount();
        	}
			decodePDF.decodePage(page);
			decodePDF.updateUI();
			view.setCurrentPage(page);
			view.repaint();       
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    }
	
	

}
